<%@ page import="entity.Course" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="util.JDBC" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: 10799
  Date: 2018/12/8
  Time: 18:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理系统</title>
    <link rel="stylesheet" type="text/css" href="statics/css/initialition.css">
    <link rel="stylesheet" type="text/css" href="statics/css/management.css">
</head>
<body>
<div id="cqr">
    <table>
        <caption>课程列表</caption>
        <tbody>
        <tr>
            <td>课程名</td>
            <td>任课老师</td>
            <td>学分</td>
            <td>操作</td>
        </tr>
        <%
            String userId="";
            try{
                userId=session.getAttribute("userId").toString();
            }catch (Exception ex){//没有userId则跳转
                response.sendRedirect("login.jsp");
            }
            JDBC.connectionTest();
            String sql="select * from course";
            ResultSet rs= JDBC.executeQuery(sql);
            List<Course> courses=new ArrayList<Course>();
            try{
                while (rs.next()){
                    Course course=new Course();
                    course.setId(rs.getInt("id"));
                    course.setCourseName(rs.getString("courseName"));
                    course.setTecher(rs.getString("teacher"));
                    course.setCredit(rs.getInt("credit"));
                    courses.add(course);
                }
            }catch (Exception ex){
                ex.printStackTrace();
            }
        %>
        <%
            for (Course course:courses){
        %>
        <tr>
            <td><%=course.getCourseName()%></td>
            <td><%=course.getTecher()%></td>
            <td><%=course.getCredit()%></td>
            <td><a v-on:click="deleteCourse(<%=course.getId()%>)">删除</a></td>
        </tr>
        <%
            }
        %>
        <tr>
            <td><input type="text" v-model="courseName"></td>
            <td><input type="text" v-model="teacher"></td>
            <td><input type="text" v-model="credit"></td>
            <td><a v-on:click="addCourse()">添加</a></td>
        </tr>
        <tr><td></td></tr>
        <tr><td></td><td></td><td></td><td><a href="login.jsp">退出管理员账号</a></td></tr>
        </tbody>
    </table>
</div>
</body>
<script src="statics/js/jquery-3.3.1.min.js"></script>
<script src="statics/js/vue.js"></script>
<script src="statics/js/management.js"></script>
</html>
